package www.openteam.com.model.business.other;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.SomeCustomInfo;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2016/11/25.
 */

public class SearchSomeCustomInfoModel extends BaseModel {

    private boolean isQuery = false;

    public boolean querySomeCustomInfo(String name, int pageSize,
                                       final SearchSomeCustomInfoOnListener searchSomeCustomInfoOnListener) {
        httpApiService.querySomeCustomInfo(name, pageSize)
                .compose(new CommonTransformer<SomeCustomInfo>())
                .subscribe(new CommonSubscriber<SomeCustomInfo>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(SomeCustomInfo someCustomInfo) {
                        isQuery = true;
                        searchSomeCustomInfoOnListener.querySCISuccess(someCustomInfo);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);

                        isQuery = false;
                        searchSomeCustomInfoOnListener.querySCIFail(e);
                    }
                });

        return isQuery;

    }


    public interface SearchSomeCustomInfoOnListener {
        void querySCISuccess(SomeCustomInfo pbProductInfo);

        void querySCIFail(Throwable throwable);
    }
}
